package com.erlinyou.im.web.wshandler;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import com.erlinyou.im.web.controller.base.SiteUtil;


@Component
public class HandshakeInterceptor extends HttpSessionHandshakeInterceptor {
	private static Logger logger = LoggerFactory.getLogger(HandshakeInterceptor.class);
    @Override
    public boolean beforeHandshake(ServerHttpRequest request,
            ServerHttpResponse response, WebSocketHandler wsHandler,
            Map<String, Object> attributes) throws Exception {
    	logger.info("握手前...");
        boolean zt=super.beforeHandshake(request, response, wsHandler, attributes);
        if(zt){
        //	return attributes.get(SiteUtil.AUTHENTICATION_KEY) != null;
        	return zt;
        }
        return zt;
    }

    @Override
    public void afterHandshake(ServerHttpRequest request,
            ServerHttpResponse response, WebSocketHandler wsHandler,
            Exception ex) {
    	logger.info("握手后...");
        super.afterHandshake(request, response, wsHandler, ex);
    }

}